package com.test.project.system.post.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.test.framework.aspectj.lang.enums.BusinessType;
import com.test.project.system.post.domain.ZhiyuanPost;
import com.test.project.system.post.service.IZhiyuanPostService;
import com.test.framework.web.controller.BaseController;
import com.test.framework.web.domain.AjaxResult;
import com.test.common.utils.poi.ExcelUtil;
import com.test.framework.web.page.TableDataInfo;

/**
 * 比赛公告Controller
 * 
 * @author test
 * @date 2023-12-05
 */
@Controller
@RequestMapping("/system/post")
public class ZhiyuanPostController extends BaseController
{
    private String prefix = "system/post";

    @Autowired
    private IZhiyuanPostService zhiyuanPostService;

    @RequiresPermissions("system:post:view")
    @GetMapping()
    public String post()
    {
        return prefix + "/post";
    }

    /**
     * 查询志愿文章列表
     */
    @RequiresPermissions("system:post:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZhiyuanPost zhiyuanPost)
    {
        startPage();
        List<ZhiyuanPost> list = zhiyuanPostService.selectZhiyuanPostList(zhiyuanPost);
        return getDataTable(list);
    }

    /**
     * 导出志愿文章列表
     */
    @RequiresPermissions("system:post:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhiyuanPost zhiyuanPost)
    {
        List<ZhiyuanPost> list = zhiyuanPostService.selectZhiyuanPostList(zhiyuanPost);
        ExcelUtil<ZhiyuanPost> util = new ExcelUtil<ZhiyuanPost>(ZhiyuanPost.class);
        return util.exportExcel(list, "post");
    }

    /**
     * 新增志愿文章
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存志愿文章
     */
    @RequiresPermissions("system:post:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZhiyuanPost zhiyuanPost)
    {
        return toAjax(zhiyuanPostService.insertZhiyuanPost(zhiyuanPost));
    }
    @GetMapping("/show/{postId}")
    public String show(@PathVariable("postId") Long postId, ModelMap mmap)
    {
    	ZhiyuanPost post = zhiyuanPostService.selectZhiyuanPostById(postId);
    	mmap.put("post", post);
    	return prefix + "/show";
    }
    /**
     * 修改志愿文章
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZhiyuanPost zhiyuanPost = zhiyuanPostService.selectZhiyuanPostById(id);
        mmap.put("zhiyuanPost", zhiyuanPost);
        return prefix + "/edit";
    }

    /**
     * 修改保存志愿文章
     */
    @RequiresPermissions("system:post:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZhiyuanPost zhiyuanPost)
    {
        return toAjax(zhiyuanPostService.updateZhiyuanPost(zhiyuanPost));
    }

    /**
     * 删除志愿文章
     */
    @RequiresPermissions("system:post:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zhiyuanPostService.deleteZhiyuanPostByIds(ids));
    }
}
